// API 配置
export const API_CONFIG = {
  // 基础URL - 开发环境使用代理，生产环境使用完整URL
  BASE_URL: import.meta.env.VITE_API_BASE_URL || "/api/v1",

  // 请求超时时间
  TIMEOUT: parseInt(import.meta.env.VITE_API_TIMEOUT) || 10000,

  // 是否开启调试模式
  DEBUG: import.meta.env.VITE_APP_DEBUG === "true",
};

// API 端点配置
export const API_ENDPOINTS = {
  // 认证相关
  AUTH: {
    REGISTER: "/auth/register",
    LOGIN: "/auth/login",
    LOGOUT: "/auth/logout",
    ME: "/auth/me",
    FORGOT_PASSWORD: "/auth/forgot-password",
    RESET_PASSWORD: "/auth/reset-password",
    VERIFY_EMAIL: "/auth/verify-email",
  },

  // 用户相关
  USER: {
    PROFILE: "/user/profile",
    AVATAR: "/user/avatar",
    PASSWORD: "/user/password",
    STATISTICS: (userId: number) => `/users/${userId}/statistics`,
    ABILITIES: (userId: number) => `/users/${userId}/abilities`,
    ABILITIES_HISTORY: (userId: number) => `/users/${userId}/abilities/history`,
    FAVORITE_CHARACTERS: (userId: number) =>
      `/users/${userId}/favorite-characters`,
  },

  // 训练相关
  TRAINING: {
    CHARACTERS: "/training/characters",
    FAVORITE_CHARACTER: (characterId: number) =>
      `/training/characters/${characterId}/favorite`,
    SCENARIOS: "/training/scenarios",
    SESSIONS: "/training/sessions",
    SESSION_DETAIL: (sessionId: number) => `/training/sessions/${sessionId}`,
    SEND_MESSAGE: (sessionId: number) =>
      `/training/sessions/${sessionId}/messages`,
    COMPLETE_SESSION: (sessionId: number) =>
      `/training/sessions/${sessionId}/complete`,
    SESSION_REVIEW: (sessionId: number) =>
      `/training/sessions/${sessionId}/review`,
    SESSION_REPLAY: (sessionId: number) =>
      `/training/sessions/${sessionId}/replay`,
  },

  // 评估相关
  ASSESSMENT: {
    QUESTIONS: "/assessment/questions",
    SUBMIT: (userId: number) => `/users/${userId}/assessment`,
    RESULT: (assessmentId: string) => `/assessment/results/${assessmentId}`,
  },

  // 成就相关
  ACHIEVEMENTS: {
    LIST: "/achievements",
    USER_ACHIEVEMENTS: (userId: number) => `/users/${userId}/achievements`,
    CHECK: (userId: number) => `/users/${userId}/achievements/check`,
  },

  // 每日挑战
  DAILY_CHALLENGES: {
    LIST: "/daily-challenges",
    TODAY: "/daily-challenges/today",
    USER_CHALLENGES: (userId: number) => `/users/${userId}/daily-challenges`,
    START: (challengeId: number) => `/daily-challenges/${challengeId}/start`,
    COMPLETE: (challengeId: number) =>
      `/daily-challenges/${challengeId}/complete`,
    CLAIM: (challengeId: number) => `/daily-challenges/${challengeId}/claim`,
    HISTORY: (userId: number) => `/daily-challenges/users/${userId}/history`,
  },

  // 社区功能
  COMMUNITY: {
    SHARES: "/community/shares",
    SHARE_INTERACT: (shareId: number) =>
      `/community/shares/${shareId}/interact`,
    SHARE_COMMENTS: (shareId: number) =>
      `/community/shares/${shareId}/comments`,
    HELP_REQUESTS: "/community/help-requests",
    HELP_ANSWERS: (requestId: number) =>
      `/community/help-requests/${requestId}/answers`,
    MARK_BEST_ANSWER: (answerId: number) =>
      `/community/help-answers/${answerId}/best`,
  },

  // 其他功能
  SOCIAL_ENERGY: "/social-energy",
  NOTIFICATIONS: (userId: number) => `/notifications/users/${userId}`,
  MARK_NOTIFICATION_READ: (notificationId: number) =>
    `/notifications/${notificationId}/read`,
  USER_TIER: (userId: number) => `/users/${userId}/tier`,
  TIER_UPGRADE: (userId: number) => `/users/${userId}/tier/upgrade`,
  CONTENT_REPORT: "/content/report",
};

// 请求方法枚举
export const HTTP_METHODS = {
  GET: "GET",
  POST: "POST",
  PUT: "PUT",
  DELETE: "DELETE",
  PATCH: "PATCH",
} as const;

// 响应状态码
export const HTTP_STATUS = {
  OK: 200,
  CREATED: 201,
  BAD_REQUEST: 400,
  UNAUTHORIZED: 401,
  FORBIDDEN: 403,
  NOT_FOUND: 404,
  UNPROCESSABLE_ENTITY: 422,
  INTERNAL_SERVER_ERROR: 500,
} as const;
